package com.vincent.template.controller.biz;

import com.vincent.template.commons.base.VctVo;
import com.vincent.template.dto.sys.user.UserCancelDto;
import com.vincent.template.dto.sys.user.UserInfoDto;
import com.vincent.template.dto.sys.user.UserPwdResetDto;
import com.vincent.template.dto.sys.user.UserRegisterDto;
import com.vincent.template.dto.sys.user.UserUpdateDto;
import com.vincent.template.service.logic.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author Vincent Wang
 * @date 2021/2/28 20:25
 */
@Api(tags = "用户")
@RestController
@RequestMapping("/user")
public class UserSelfController {

    @Autowired
    private UserService userService;

    @ApiOperation("根据用户Id查询用户信息")
    @GetMapping("/{id}")
    public UserInfoDto findUserInfo(@PathVariable("id") String id) {
        return userService.findUserById(id);
    }

    @ApiOperation("用户注册")
    @PostMapping("/register")
    public VctVo<String> register(@Validated @RequestBody UserRegisterDto registerDto) {
        return VctVo.id(userService.register(registerDto));
    }

    @ApiOperation("用户重置密码")
    @PostMapping("/{id}/pwdReset")
    public boolean resetPwd(@PathVariable("id") String id,
                            @Validated @RequestBody UserPwdResetDto pwdResetDto) {
        return userService.resetPwd(id, pwdResetDto);
    }

    @ApiOperation("用户更新信息")
    @PutMapping("/{id}/update")
    public boolean updateInfo(@PathVariable("id") String id,
                              @Validated @RequestBody UserUpdateDto updateDto) {
        return userService.updateInfo(id, updateDto);
    }

    @ApiOperation("用户注销")
    @DeleteMapping("/selfCancel")
    public boolean selfCancel(UserCancelDto cancelDto) {
        return userService.selfCancel(cancelDto);
    }

}
